import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Practice_c3p0 {
    public static void main(String[] args) throws PropertyVetoException, SQLException {
        ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
        comboPooledDataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
        comboPooledDataSource.setJdbcUrl("jdbc:mysql://localhost:3306/manger");
        comboPooledDataSource.setUser("root");
        comboPooledDataSource.setPassword("");
        comboPooledDataSource.setInitialPoolSize(5);
        Connection connection = comboPooledDataSource.getConnection();
        System.out.println(connection);
        //执行SQL语句
        PreparedStatement statement = connection.prepareStatement("select * from account");
        ResultSet resultSet = statement.executeQuery();
        while (resultSet.next()){
            int id = resultSet.getInt("id");
            double balance = resultSet.getDouble("balance");
            String commit  = resultSet.getString("commit");
            System.out.println("编号：" + id + ",余额：" + balance + ",备注：" + commit);
        }
        resultSet.close();
        statement.close();
        connection.close();
        comboPooledDataSource.close();
    }
}
